package lsy.redis001.lsyredis001.controller;

import lsy.redis001.lsyredis001.common.entity.PageResult;
import lsy.redis001.lsyredis001.common.response.RespEntity;
import lsy.redis001.lsyredis001.entity.Article;
import lsy.redis001.lsyredis001.service.impl.ArticleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/article")
public class ArticleController {
    @Autowired
    private ArticleServiceImpl articleService;

    @GetMapping("/page")
    public PageResult<Article> page(@RequestParam Long page){
        PageResult<Article> pageResult = articleService.listPage(page, 10L);
        return pageResult;
    }

    @GetMapping("/get")
    public RespEntity<Article> get(@RequestParam Long id){
        Article article = articleService.getOne(id);
        return RespEntity.success(article);
    }

    @GetMapping("/delete")
    public RespEntity<Boolean> delete(@RequestParam Long id){
        Boolean b = articleService.deleteArticle(id);
        return RespEntity.success(b);
    }
}
